package com.x.service.di.modules;

import android.app.Application;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.x.service.api.BookApi;
import com.x.service.api.DataRepository;
import com.x.service.api.ZssqApi;
import com.x.service.entity.map.MapManger;

import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

@Module
public class APIModule {
    private Application application;

    public APIModule(Application application) {
        this.application = application;
    }

    @Provides
    @Singleton
    public HttpLoggingInterceptor provideHttpLoggingInterceptor() {
        return new HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.NONE);
    }

    @Provides
    @Singleton
    public OkHttpClient provideOkHttpClient(HttpLoggingInterceptor interceptor) {
        return new OkHttpClient.Builder()
                .addInterceptor(interceptor)
                .connectTimeout(60 * 1000, TimeUnit.MILLISECONDS)
                .writeTimeout(60 * 1000, TimeUnit.MILLISECONDS)
                .readTimeout(60 * 1000, TimeUnit.MILLISECONDS)
                .build();
    }

    @Provides
    @Singleton
    public BookApi provideBookApi(OkHttpClient okHttpClient) {
        return BookApi.getInstance(okHttpClient);
    }

    @Provides
    @Singleton
    public com.x.zssqservice.api.BookApi provideZssqBookApi(OkHttpClient okHttpClient) {
        return com.x.zssqservice.api.BookApi.getInstance(okHttpClient);
    }

    @Provides
    @Singleton
    public MapManger provideMapManger() {
        return new MapManger();
    }

    @Provides
    @Singleton
    public Gson provideGson() {
        return new GsonBuilder()
                .excludeFieldsWithoutExposeAnnotation()
                .create();
    }

    @Provides
    @Singleton
    public DataRepository provideDataRepository(BookApi xBookApi, com.x.zssqservice.api.BookApi bookApi
            , MapManger mapManger, OkHttpClient okHttpClient) {
//        return new ZssqApi(bookApi, xBookApi, mapManger);
        return xBookApi;
    }
}
